package utils

import (
	"bytes"
	"encoding/csv"
	"golang.org/x/text/encoding/simplifiedchinese"
	"golang.org/x/text/transform"
	"log"
)

func DecodeStingHttpResponse(body []byte, resp *[][]string, debug bool) error {
	// 转码
	reader := transform.NewReader(bytes.NewReader(body), simplifiedchinese.GBK.NewDecoder())
	a := csv.NewReader(reader)
	a.Comma = ','   // 设置自定义的分隔符为逗号
	a.Comment = '#' // 设置自定义的注释符为井号
	a.LazyQuotes = true
	body2, err := a.ReadAll()
	if err != nil {
		return err
	}
	*resp = body2
	if debug {
		log.Printf("[DEBUG] [API] http response body:\n%s\n", body2)
	}

	return nil
}
